Skip to content

refactor: split buzz/api into domain packages - #295

Merged
harshtandiya merged 4 commits into
developfrom
refactor/api-move
Jul 29, 2026
Merged

refactor: split buzz/api into domain packages#295
harshtandiya merged 4 commits into
developfrom
refactor/api-move

Conversation

@harshtandiya

@harshtandiya harshtandiya commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Splits the 1364-line buzz/api/__init__.py into one package per domain. In Frappe the module path is the URL, so this also renames every endpoint: buzz.api.process_bookingbuzz.api.booking.process_booking.

buzz/api/
  schemas.py     APIRequest / APIResponse
  exceptions.py  BuzzAPIError + shared subclasses
  account/ auth/ booking/ campaigns/ checkin/
  forms/ payments/ proposals/ sponsorships/ tickets/

Move only. Bodies are verbatim — no models, no service classes, no dead-code removal. Those are per-domain follow-ups, and they stay independent because api/__init__.py is already empty by then.

0856863 adds the shared bases the follow-ups need. Two non-obvious bits:

  • APIResponse.__json__json_handler checks __json__ before Iterable, and BaseModel is iterable. Without it a returned model serializes as (key, value) pairs.
  • BuzzAPIError.throw() — a bare raise skips msgprint, so nothing lands in _server_messages and the dashboard shows "Internal Server Error". throw() makes that unreachable. Copy uses _lt because class bodies run at import, before a request has a language.

No back-compat shims. Callers updated: hooks.py, event_booking.py, 6 test modules (incl. 18 patch("buzz.api...") sites), 18 dashboard files, ARCHITECTURE.md.

Checks: 171 tests green across the 8 affected modules, +7 new in test_exceptions. All 31 endpoint paths resolve via frappe.handler.get_attr. ruff / pre-commit / yarn typecheck clean. No dev server was up, so no live devtools diff.

Deferred: booking/ is 679 lines, tickets/ 324 — both over the 300 target. Splitting them is scope for their own PRs.

🤖 Generated with Claude Code

harshtandiya and others added 3 commits July 28, 2026 18:40
buzz/api/__init__.py held 1364 lines covering booking, tickets,
sponsorships, check-in, account, campaigns and coupons in one module.
Since a Frappe endpoint's URL is its dotted module path, that layout also
made the public API surface unreadable.

Each domain now owns a package, so an endpoint's URL names its domain:
buzz.api.booking.process_booking rather than buzz.api.process_booking.
forms.py, auth.py and proposals.py become packages of the same shape.

Function bodies are unchanged; this is relocation only. Landed alongside
are api/schemas.py and api/exceptions.py, the pydantic and error base
classes later PRs build on, currently unused.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Follows the backend split: every createResource url moves from
buzz.api.<fn> to buzz.api.<domain>.<fn>. String changes only.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

The base error carried only http_status_code, so every call site still had
to pass its own message string and no default copy existed.

Subclasses now declare title and message as class attributes, raised via a
throw() classmethod:

    class AlreadyRegistered(Conflict):
        title = _lt("Already Registered")
        message = _lt("You have already registered your interest.")

    AlreadyRegistered.throw()

throw() routes through frappe.throw so the text lands in _server_messages,
which is what the dashboard reads as err.messages[0]. A bare raise skips
msgprint and leaves the user with "Internal Server Error" — covered by a
test so the distinction stays visible.

Messages use _lt rather than _ because class bodies run at import, before a
request has a language. frappe's translation extractor already scans _lt.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@harshtandiya
harshtandiya merged commit 66396ad into develop Jul 29, 2026
9 checks passed
@harshtandiya
harshtandiya deleted the refactor/api-move branch July 29, 2026 15:55
@github-actions

Copy link
Copy Markdown
Contributor

Successfully created backport PR for main:

harshtandiya added a commit that referenced this pull request Jul 29, 2026
Brings main to parity with develop at a4f52b2: the buzz/api domain package
split (#295-#303), the shared bench setup action (#305), and the backport
workflow (#273, #291). Tree is identical to develop at a4f52b2.
harshtandiya added a commit that referenced this pull request Jul 29, 2026
Brings main to parity with develop at a4f52b2: the buzz/api domain package
split (#295-#303), the shared bench setup action (#305), and the backport
workflow (#273, #291). Tree is identical to develop at a4f52b2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport main backport to main branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant